#!/bin/sh
nucli=`uname -r`
if [ -f makeliveusbcd-$nucli.deb ]; then
mv makeliveusbcd-$nucli.deb makeliveusbcd-$nucli.deb.bak
fi
rm -f makeliveusbcd-*.deb
amd=`uname -m | grep 64`
develdir=`pwd`
cp -a /usr/lib/grub/*/* $develdir/makeliveusbcd/etc/initramfs-tools-live/MASTERLIVEUSBCD/boot/grub/
dir=`basename $develdir`
temp=/tmp/$dir
mkdir -p $temp
cp -a ./* $temp/
find $temp -type d -name .svn -print0 | xargs -0 rm -rf 
cd $temp/makeliveusbcd
cat  DEBIAN/control | sed "s/KERNEL/$nucli/g" > DEBIAN/control.new
mv DEBIAN/control.new DEBIAN/control
if [ "$amd" != "" ]; then
cat  DEBIAN/control | sed "s/i386/amd64/g" > DEBIAN/control.new
mv DEBIAN/control.new DEBIAN/control
fi
chmod -R og=rX .
rm -f DEBIAN/md5sums
find usr -type f -exec md5sum {} \; > DEBIAN/md5sums
cd ..
tar cz -C makeliveusbcd/DEBIAN -f control.tar.gz .
tar cz --exclude=DEBIAN -C makeliveusbcd -f data.tar.gz .
echo 2.0 > debian-binary
ar rcu makeliveusbcd-$nucli.deb debian-binary control.tar.gz data.tar.gz
rm -f *.gz
cp -a makeliveusbcd-$nucli.deb $develdir/
rm -rf $temp
